using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Collections;

namespace Microsoft.PowerShell.CmdletManagement
{
    [System.Windows.Markup.ContentProperty("Label")]
    public partial class ExtendedListBox : System.Windows.Controls.UserControl
    {
        public ExtendedListBox()
        {
            InitializeComponent();

            Items.IsEnabled = false;
        }

        public string Label
        {
            get { return (string) GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }
        }

        public string SelectedValue
        {
            get { return (string) GetValue(SelectedValueProperty); }
            set { SetValue(SelectedValueProperty, value); }
        }

        public string HelpText
        {
            get { return (string) GetValue(HelpTextProperty); }
            set { SetValue(HelpTextProperty, value); }
        }

        public bool IsReadOnly
        {
            get { return (bool)GetValue(IsReadOnlyProperty); }
            set { SetValue(IsReadOnlyProperty, value); }
        }

        private static void OnIsReadOnlyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ExtendedListBox listBox = d as ExtendedListBox;

            if (((bool)e.NewValue) == true)
            {
                listBox.Items.IsEnabled = false;
            }
            else
            {
                listBox.Items.IsEnabled = true;
            }
        }

        public static readonly DependencyProperty LabelProperty =
            DependencyProperty.Register("Label", typeof(string), typeof(ExtendedListBox));
        public static readonly DependencyProperty PrimaryFieldProperty =
            DependencyProperty.Register("PrimaryField", typeof(string),  typeof(ExtendedListBox),
            new PropertyMetadata("Name"));
        public static readonly DependencyProperty HelpTextProperty =
            DependencyProperty.Register("HelpText", typeof(string), typeof(ExtendedListBox));
        public static readonly DependencyProperty SelectedValueProperty =
            DependencyProperty.Register("SelectedValue", typeof(string), typeof(ExtendedListBox));
        public static readonly DependencyProperty IsReadOnlyProperty =
            DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(ExtendedListBox),
            new FrameworkPropertyMetadata(true, new PropertyChangedCallback(OnIsReadOnlyChanged)));
     }
}